/**
 * Created by icyhy on 2017/5/23.
 */
"use strict";
var builder = require("../response/rest.result.builder.js");
var checkRecordModel = require("../models/check.record");

module.exports = {

  create : function (req, res, next) {
    var checkRecordEntity = new checkRecordModel(req.body);
    console.log(checkRecordEntity);
    checkRecordModel.create(checkRecordEntity, function(err) {
      if (err) return next(err);

      return builder.buildSuccessResultInfo(res);
    });
  },
  getListByDoc:function(req, res, next){
    var docId = req.params.id || '';
    checkRecordModel.find({'docId':docId}).exec(function(err, records) {
      if (err) return next(err);
      if (!records) return next(new Error('records not found'));

      return builder.buildSuccessResultInfoWithData(res,records);
    });
  },
  getById:function(req, res, next){
    var id = req.params.id || '';
    checkRecordModel.findOne({
      _id: id
    })
      .exec(function(err, record) {
        if (err) return next(err);
        if (!record) return next(new Error('not  found'));

        return builder.buildSuccessResultInfo(res, record);
      });
  },
}
